﻿@using Nop.Core
@using Nop.Services.Common
@{
    const string panelId = "order-average-report-box";
    const string hidePanelAttributeName = "HideOrderAverageReportPanel";
    var hidePanel = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.GetAttribute<bool>(hidePanelAttributeName);
}

<div class="box box-info @if(hidePanel){<text>collapsed-box</text>}" id="@panelId">
    <div class="box-header with-border">
        <h3 class="box-title">
            <i class="fa fa-money"></i>
            @T("Admin.SalesReport.Average")
        </h3>
        <div class="box-tools pull-right">
            <button class="btn btn-box-tool" data-widget="collapse">
                @if (hidePanel)
                {
                    <text><i class="fa fa-plus"></i></text>
                }
                else
                {
                    <text><i class="fa fa-minus"></i></text>
                }
            </button>
        </div>
    </div>
    <div class="box-body" style="padding-bottom: 22px;">
        <div id="average-order-report-grid"></div>

        <script>
            $(document).ready(function () {
                $('#@panelId').on('click', 'button[data-widget="collapse"]', function () {
                    var collapsed = !$('#@panelId').hasClass('collapsed-box');
                    saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hidePanelAttributeName', collapsed);
                });

                $("#average-order-report-grid").kendoGrid({
                    dataSource: {
                        type: "json",
                        transport: {
                            read: {
                                url: "@Html.Raw(Url.Action("OrderAverageReportList", "Order"))",
                                type: "POST",
                                dataType: "json",
                                data: addAntiForgeryToken
                            }
                        },
                        schema: {
                            data: "Data",
                            total: "Total",
                            errors: "Errors"
                        },
                        error: function (e) {
                            display_kendoui_grid_error(e);
                            // Cancel the changes
                            this.cancelChanges();
                        },
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    pageable: {
                        refresh: true,
                        numeric: false,
                        previousNext: false,
                        info: false,
                        @Html.Partial("_GridPagerMessages")
                    },
                    editable: {
                        confirmation: "@T("Admin.Common.DeleteConfirmation")",
                        mode: "inline"
                    },
                    scrollable: false,
                    columns: [{
                        field: "OrderStatus",
                        title: "@T("Admin.SalesReport.Average.OrderStatus")"
                    }, {
                        field: "SumTodayOrders",
                        title: "@T("Admin.SalesReport.Average.SumTodayOrders")"
                    }, {
                        field: "SumThisWeekOrders",
                        title: "@T("Admin.SalesReport.Average.SumThisWeekOrders")"
                    }, {
                        field: "SumThisMonthOrders",
                        title: "@T("Admin.SalesReport.Average.SumThisMonthOrders")"
                    }, {
                        field: "SumThisYearOrders",
                        title: "@T("Admin.SalesReport.Average.SumThisYearOrders")"
                    }, {
                        field: "SumAllTimeOrders",
                        title: "@T("Admin.SalesReport.Average.SumAllTimeOrders")"
                    }]
                });
            });
        </script>
    </div>
</div>